import ApiPrefix from './prefix'
const dev = {
  '/basicApi': {
    target: 'http://localhost:23333', //测试环境
    changeOrigin: true,
    rewrite: (path: string) => path.replace(/^\/basicApi/, '')
  },
  '/adminApi': {
    target: 'http://localhost:8849', //测试环境
    changeOrigin: true,
    rewrite: (path: string) => path.replace(/^\/adminApi/, '/')
  },
  '/fileApi': {
    target: 'http://localhost:8850', //测试环境
    changeOrigin: true,
    rewrite: (path: string) => path.replace(/^\/fileApi/, '/')
  },
  '/searchApi': {
    target: 'http://localhost:8851', //测试环境
    changeOrigin: true,
    rewrite: (path: string) => path.replace(/^\/searchApi/, '/')
  },
  '/baidu': {
    // 此处的写法，目的是为了 将 /api 替换成 https://www.baidu.com/
    target: 'https://14.119.104.189:443/',
    // 允许跨域
    changeOrigin: true,
    ws: true,
    pathRewrite: {
      '^/baidu': '/'
    }
  },
  '/ktApi': {
    // 此处的写法，目的是为了 将 /api 替换成 https://www.baidu.com/
    target: 'http://192.168.1.83:10081/',
    // 允许跨域
    changeOrigin: true,
    ws: true,
    pathRewrite: {
      '^/ktApi': '/'
    }
  },
  '/platformApi': {
    // 此处的写法，目的是为了 将 /api 替换成 https://www.baidu.com/
    target: 'http://localhost:10084/',
    // 允许跨域
    changeOrigin: true,
    ws: true,
    rewrite: (path: string) => path.replace(/^\/platformApi/, '/')
  },
}
const prod = {
  '/baseApi': {
    target: 'http://localhost:8848', //测试环境
    changeOrigin: true,
    rewrite: (path: string) => path.replace(/^\/baseApi/, '')
  },
  '/adminApi': {
    target: 'http://localhost:8849', //测试环境
    changeOrigin: true,
    rewrite: (path: string) => path.replace(/^\/adminApi/, '')
  },
  '/searchApi': {
    target: 'http://localhost:8851', //测试环境
    changeOrigin: true,
    rewrite: (path: string) => path.replace(/^\/searchApi/, '/')
  },
  '/platformApi': {
    // 此处的写法，目的是为了 将 /api 替换成 https://www.baidu.com/
    target: 'http://192.168.1.58:6300/cssc-platform-api/',
    // 允许跨域
    changeOrigin: true,
    ws: true,
    rewrite: (path: string) => path.replace(/^\/platformApi/, '/')
  },
}
const mock = {
  '/baseApi': {
    target: 'http://localhost:8848', //测试环境
    changeOrigin: true,
    rewrite: (path: any) => path.replace(/^\/baseApi/, '')
  },
  '/adminApi': {
    target: 'http://localhost:8849', //测试环境
    changeOrigin: true,
    rewrite: (path: any) => path.replace(/^\/adminApi/, '/mock')
  },
  '/fileApi': {
    target: 'http://localhost:8850', //测试环境
    changeOrigin: true,
    rewrite: (path: any) => path.replace(/^\/fileApi/, '/')
  },
  '/searchApi': {
    target: 'http://localhost:8851', //测试环境
    changeOrigin: true,
    rewrite: (path: any) => path.replace(/^\/searchApi/, '/')
  }
}

// const env=p => p.env || 'prod' // default to prod if not set or if set to 'dev' or 'prod'
const env = process.env.NODE_ENV || 'production' //如果没有NODE_ENV的话，则使用生产环境。如果你不想测试任何环境，可以将其设置为production。
const getProxy = () => {
  console.log('environment:' + env)
  switch (process.env.NODE_ENV) {
    case 'production':
      return prod
      break
    case 'development':
      return dev
      break
    case 'mock':
      return mock
      break
    default:
      break
  }
}
const Proxy = getProxy()

export default Proxy
